package calao.storage;

public abstract class SchemaElement 
{
	
	final String name;
	
	Schema schema;
	
	protected SchemaElement(String name)
	{
		this.name = name;
	}

	public String getName() 
	{
		return name;
	}
	
	abstract protected void register() throws InvalidSchemaException;

	public Schema getSchema() 
	{
		return schema;
	}
	
	/** Checks whether this element belongs to a registered schema.
	 */
	public boolean isRegistered()
	{
		return schema!=null && schema.registered;
	}
	
	protected void ensureNotRegistered()
	{
		if (isRegistered()) {
			throw new IllegalStateException("Cannot alter registered schema element");
		}
	}
	
	/** Lists child elements.
	 * Child elements will be registered before their parent.
	 */
	public Iterable<SchemaElement> getChildElements()
	{
		return java.util.Collections.emptyList();
	}

}
